﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Glorysoft.Auto.Xfw;
using Glorysoft.EAP.Core;
using Glorysoft.EAP.Core.Enums;
using Glorysoft.EAP.EAPClient.Common;
using Glorysoft.EAP.EAPClient.ViewModel;
using Serilog.Core;
using System;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Windows;

namespace Glorysoft.EAP.EAPClient.Model
{
    public class EqpClientInfo : ViewModelBase
    {
        private readonly Logger ServiceLogger = XfwContext.EapLogger;
        [DllImport("user32.dll")]
        public static extern int MessageBeep(uint uType);
        [DllImport("kernel32.dll")]
        private static extern int Beep(int dwFreq, int dwDuration);
        [DllImport("winmm.dll")]
        public static extern bool PlaySound(String Filename, int Mod, int Flags);
        //public EqpClientInfo(string EqpName, int portNumbers)
        //{
        //    LotList = new ObservableCollection<C_LotInfo>();
        //    for (int i = 1; i <= portNumbers; i++)
        //    {
        //        LotList.Add(new C_LotInfo() { EqpId = EqpName, XNameId = EqpName + "-" + i, portid = i.ToString(), portnumber = portNumbers.ToString() });
        //    }
        //}
        public EqpClientInfo(string EqpName)
        {
            var lot = new C_LotInfo();
            lot.EqpId = EqpName;
            if (Dict.Current.EAPName == "EAPServer"|| Dict.Current.EAPName == "EAPServer_OCR" || Dict.Current.EAPName == "EAPServer_ETS88")
            {
                lot.Groupbox1 = Visibility.Visible;//Type1
            }
            else if (Dict.Current.EAPName == "EAPTelKeysight" || Dict.Current.EAPName == "EAPTelKeysight2")
            {
                lot.Groupbox2 = Visibility.Visible; //type2  AY
            }
            else
            {
                lot.Groupbox3 = Visibility.Visible; //type3  BYWAT  AMIDA
            }

            //lot.SlotMaps = null;
            LotList = new ObservableCollection<C_LotInfo>();
            LotList.Add(lot);

        }
        private string CopyMsg = "";
        private object lockobj = new object();
        #region 属性封装
        private object lock2obj = new object();
        /// <summary>
        /// Login用户名
        /// </summary>
        private string userId;
        public string UserId
        {
            get { return userId; }
            set
            {
                userId = value;

            }
        }
        /// <summary>
        /// 设备port数量
        /// </summary>
        private int portNumber;
        public int PortNumber
        {
            get { return portNumber; }
            set
            {
                portNumber = value;
            }
        }

        private string testmodelist;
        public string TestmodeList
        {
            get { return testmodelist; }
            set
            {
                testmodelist = value;
            }
        }
        /// <summary>
        /// 实时消息提示
        /// </summary>
        private ObservableCollection<InstantMsg> mMsg = new ObservableCollection<InstantMsg>();
        public ObservableCollection<InstantMsg> MMSG
        {
            get { return mMsg; }
            set
            {
                mMsg = value;
                RaisePropertyChanged("MMSG");
            }
        }

        /// <summary>
        /// 设备显示/隐藏
        /// </summary>
        private Visibility vis = Visibility.Visible;
        public Visibility Vis
        {
            get { return vis; }
            set
            {
                vis = value;
                RaisePropertyChanged("Vis");
            }
        }
        private Visibility btnok = Visibility.Hidden;
        public Visibility BtnOk
        {
            get { return btnok; }
            set
            {
                btnok = value;
                RaisePropertyChanged("BtnOk");
            }
        }
        private Visibility btnclean;
        public Visibility Btnclean
        {
            get { return btnclean; }
            set
            {
                btnclean = value;
                RaisePropertyChanged("Btnclean");
            }
        }
        private Visibility loginout;
        public Visibility Loginout
        {
            get { return loginout; }
            set
            {
                loginout = value;
                RaisePropertyChanged("Loginout");
            }
        }
        private Visibility loginin;
        public Visibility Loginin
        {
            get { return loginin; }
            set
            {
                loginin = value;
                RaisePropertyChanged("Loginin");
            }
        }
        private Visibility lab_Probercard = Visibility.Hidden;
        public Visibility Lab_Probercard
        {
            get { return lab_Probercard; }
            set
            {
                lab_Probercard = value;
                RaisePropertyChanged("Lab_Probercard");
            }
        }

        private Visibility txt_ProberCardID = Visibility.Hidden;
        public Visibility Txt_ProberCardID
        {
            get { return txt_ProberCardID; }
            set
            {
                txt_ProberCardID = value;
                RaisePropertyChanged("Txt_ProberCardID");
            }
        }
        private Visibility lab_Alignment = Visibility.Hidden;
        public Visibility Lab_Alignment
        {
            get { return lab_Alignment; }
            set
            {
                lab_Alignment = value;
                RaisePropertyChanged("Lab_Alignment");
            }
        }
        private Visibility alignmentYes = Visibility.Hidden;
        public Visibility AlignmentYes
        {
            get { return alignmentYes; }
            set
            {
                alignmentYes = value;
                RaisePropertyChanged("AlignmentYes");
            }
        }
        private Visibility alignmentNo = Visibility.Hidden;
        public Visibility AlignmentNo
        {
            get { return alignmentNo; }
            set
            {
                alignmentNo = value;
                RaisePropertyChanged("AlignmentNo");
            }
        }
        /// <summary>
        /// type1
        /// </summary>
        private Visibility lbl_chipselecttype1 = Visibility.Hidden;
        public Visibility Lbl_chipselecttype1
        {
            get { return lbl_chipselecttype1; }
            set
            {
                lbl_chipselecttype1 = value;
                RaisePropertyChanged("Lbl_chipselecttype1");
            }
        }
        private Visibility autoSelectWaferTesttype1 = Visibility.Hidden;
        public Visibility AutoSelectWaferTesttype1
        {
            get { return autoSelectWaferTesttype1; }
            set
            {
                autoSelectWaferTesttype1 = value;
                RaisePropertyChanged("AutoSelectWaferTesttype1");
            }
        }
        private Visibility manualSelectWaferTesttype1 = Visibility.Hidden;
        public Visibility ManualSelectWaferTesttype1
        {
            get { return manualSelectWaferTesttype1; }
            set
            {
                manualSelectWaferTesttype1 = value;
                RaisePropertyChanged("ManualSelectWaferTesttype1");
            }
        }/// <summary>
         /// type2
         /// </summary>

        private Visibility lbl_chipselecttype2 = Visibility.Hidden;
        public Visibility Lbl_chipselecttype2
        {
            get { return lbl_chipselecttype2; }
            set
            {
                lbl_chipselecttype2 = value;
                RaisePropertyChanged("Lbl_chipselecttype2");
            }
        }
        private Visibility autoSelectWaferTesttype2 = Visibility.Hidden;
        public Visibility AutoSelectWaferTesttype2
        {
            get { return autoSelectWaferTesttype2; }
            set
            {
                autoSelectWaferTesttype2 = value;
                RaisePropertyChanged("AutoSelectWaferTesttype2");
            }
        }
        private Visibility manualSelectWaferTesttype2 = Visibility.Hidden;
        public Visibility ManualSelectWaferTesttype2
        {
            get { return manualSelectWaferTesttype2; }
            set
            {
                manualSelectWaferTesttype2 = value;
                RaisePropertyChanged("ManualSelectWaferTesttype2");
            }
        }
        /// <summary>
        /// type3
        /// </summary>
        private Visibility lbl_chipselecttype3 = Visibility.Hidden;
        public Visibility Lbl_chipselecttype3
        {
            get { return lbl_chipselecttype3; }
            set
            {
                lbl_chipselecttype3 = value;
                RaisePropertyChanged("Lbl_chipselecttype3");
            }
        }
        private Visibility autoSelectWaferTesttype3 = Visibility.Hidden;
        public Visibility AutoSelectWaferTesttype3
        {
            get { return autoSelectWaferTesttype3; }
            set
            {
                autoSelectWaferTesttype3 = value;
                RaisePropertyChanged("AutoSelectWaferTesttype3");
            }
        }
        private Visibility manualSelectWaferTesttype3 = Visibility.Hidden;
        public Visibility ManualSelectWaferTesttype3
        {
            get { return manualSelectWaferTesttype3; }
            set
            {
                manualSelectWaferTesttype3 = value;
                RaisePropertyChanged("ManualSelectWaferTesttype3");
            }
        }
        /// <summary>
        /// 针痕检测栏位
        /// </summary>
        private Visibility lab_checkZH = Visibility.Hidden;
        public Visibility Lab_CheckZH
        {
            get { return lab_checkZH; }
            set
            {
                lab_checkZH = value;
                RaisePropertyChanged("Lab_CheckZH");
            }
        }
        private Visibility checkZHYes = Visibility.Hidden;
        public Visibility CheckZHYes
        {
            get { return checkZHYes; }
            set
            {
                checkZHYes = value;
                RaisePropertyChanged("CheckZHYes");
            }
        }
        private Visibility checkZHNo = Visibility.Hidden;
        public Visibility CheckZHNo
        {
            get { return checkZHNo; }
            set
            {
                checkZHNo = value;
                RaisePropertyChanged("CheckZHNo");
            }
        }

        private Visibility testmode = Visibility.Hidden;
        public Visibility TestMode
        {
            get { return testmode; }
            set
            {
                testmode = value;
                RaisePropertyChanged("TestMode");
            }
        }
        /// <summary>
        /// 进度条
        /// </summary>
        private Visibility isProcessVisibity = Visibility.Hidden;
        public Visibility IsProcessVisibity
        {
            get { return isProcessVisibity; }
            set
            {
                isProcessVisibity = value;
                RaisePropertyChanged("IsProcessVisibity");
            }
        }
        /// <summary>
        /// 车间号
        /// </summary>
        private string facilityId;
        public string FacilityId
        {
            get { return facilityId; }
            set
            {
                facilityId = value;

            }
        }
        /// <summary>
        /// tester设备名
        /// </summary>
        private string eapname;
        public string EqpName
        {
            get { return eapname; }
            set
            {
                eapname = value;

            }
        }
        /// <summary>
        /// prober
        /// </summary>
        private string probername;
        public string ProberName
        {
            get { return probername; }
            set
            {
                probername = value;

            }
        }
        private string testername;
        public string TesterName
        {
            get { return testername; }
            set
            {
                testername = value;

            }
        }
        private string needleMaterialType1;
        public string NeedleMaterialType1
        {
            get { return needleMaterialType1; }
            set
            {
                needleMaterialType1 = value;
            }
        }
        private string needleMaterialType2;
        public string NeedleMaterialType2
        {
            get { return needleMaterialType2; }
            set
            {
                needleMaterialType2 = value;
            }
        }

        /// <summary>
        /// 设备名
        /// </summary>
        private string listHearMsg = Consts.GetTranslation("Msg_RealtimeInfo");
        public string ListHearMsg
        {
            get { return listHearMsg; }
            set
            {
                listHearMsg = value;
                RaisePropertyChanged("ListHearMsg");
            }
        }
        /// <summary>
        /// 设备名
        /// </summary>
        private string boxHearMsg = Consts.GetTranslation("Msg_WaferInfo");
        public string BoxHearMsg
        {
            get { return boxHearMsg; }
            set
            {
                boxHearMsg = value;
                RaisePropertyChanged("BoxHearMsg");
            }
        }
        /// <summary>
        /// 自动/手动切换状态
        /// </summary>
        private bool auotoProcess = true;
        public bool AuotoProcess
        {
            get
            {
                return auotoProcess;
            }
            set
            {
                if (value)
                {

                    ConnText = "EAP OnLine";
                    BGround = "Green";
                    IsEnabled = true;

                }
                else
                {
                    ConnText = "EAP OffLine";
                    BGround = "Gold";
                    IsEnabled = false;

                }
                auotoProcess = value;
            }
        }
        /// <summary>
        /// 连接状态
        /// </summary>
        private bool connStatus;
        public bool ConnStatus
        {
            get
            {
                return connStatus;
            }
            set
            {
                if (value)
                {
                    BGround = "Green";
                    //ConnText = "EAP ONLINE";
                    IsEnabled = true;
                }
                else
                {
                    BGround = "Red";
                    //ConnText = "EAP OFFLINE";
                    IsEnabled = false;
                }
                connStatus = value;
            }
        }
        private bool BindhostConnect = false;
        public bool BindHostConnect
        {
            get
            {
                return BindhostConnect;
            }

            set
            {
                if (BindhostConnect != value)
                    BindhostConnect = value;
                RaisePropertyChanged("BindHostConnect");
            }
        }
        /// <summary>
        /// 设备连接状态
        /// </summary>
        private bool eQPconnStatus = false;
        public bool EQPConnStatus
        {
            get
            {
                return eQPconnStatus;
            }
            set
            {
                if (value)
                {
                    EQPBGround = "Green";
                }
                else
                {
                    EQPBGround = "Red";
                }
                eQPconnStatus = value;
            }
        }

        private bool proberStatus = false;
        public bool ProberStatus
        {
            get
            {
                return proberStatus;
            }
            set
            {
                if (value)
                {
                    ProberBGround = "Green";
                }
                else
                {
                    ProberBGround = "Red";
                }
                proberStatus = value;
            }
        }

        private bool testerStatus = false;
        public bool TesterStatus
        {
            get
            {
                return testerStatus;
            }
            set
            {
                if (value)
                {
                    TesterBGround = "Green";
                }
                else
                {
                    TesterBGround = "Red";
                }
                testerStatus = value;
            }
        }

        private bool rcmStatus = false;
        public bool RcmStatus
        {
            get
            {
                return testerStatus;
            }
            set
            {
                if (value)
                {
                    RcmBGround = "Green";
                }
                else
                {
                    RcmBGround = "Red";
                }
                rcmStatus = value;
            }
        }

        /// <summary>
        /// 是否启用
        /// </summary>
        private bool isEnabled;
        public bool IsEnabled
        {
            get { return isEnabled; }
            set { isEnabled = value; RaisePropertyChanged("IsEnabled"); }
        }
        /// <summary>
        /// 是否悬浮
        /// </summary>
        private bool isMouseOver = true;
        public bool IsMouseOver
        {
            get { return isMouseOver; }
            set { isMouseOver = value; RaisePropertyChanged("IsMouseOver"); }
        }
        private string _MouseMargin = "0,0,0,0";
        public string MouseMargin
        {
            get { return _MouseMargin; }
            set { _MouseMargin = value; RaisePropertyChanged("MouseMargin"); }
        }
        /// <summary>
        /// 是否显示
        /// </summary>
        private string isVisibility;
        public string IsVisibility
        {
            get { return isVisibility; }
            set { isVisibility = value; RaisePropertyChanged("IsVisibility"); }
        }
        private string bGround;
        public string BGround
        {
            get { return bGround; }
            set { bGround = value; RaisePropertyChanged("BGround"); }
        }
        private string eQPbGround;
        public string EQPBGround
        {
            get { return eQPbGround; }
            set { eQPbGround = value; RaisePropertyChanged("EQPBGround"); }
        }
        /// <summary>
        /// Prober状态
        /// </summary>
        private string proberbGround;
        public string ProberBGround
        {
            get { return proberbGround; }
            set { proberbGround = value; RaisePropertyChanged("ProberBGround"); }
        }
        /// <summary>
        /// Tester状态
        /// </summary>
        private string testerbGround;
        public string TesterBGround
        {
            get { return testerbGround; }
            set { testerbGround = value; RaisePropertyChanged("TesterBGround"); }
        }

        private string rcmbGround;
        public string RcmBGround
        {
            get { return rcmbGround; }
            set { rcmbGround = value; RaisePropertyChanged("RcmBGround"); }
        }

        /// <summary>
        /// EAP连接显示
        /// </summary>
        private string connText;
        public string ConnText
        {
            get { return connText; }
            set { connText = value; RaisePropertyChanged("ConnText"); }
        }
        public bool IsLoginOpen;
        private ObservableCollection<C_LotInfo> _LotList = new ObservableCollection<C_LotInfo>();
        public ObservableCollection<C_LotInfo> LotList
        {
            get { return _LotList; }
            set
            {
                _LotList = value;
                RaisePropertyChanged("LotList");
            }
        }
        /// <summary>
        /// 实时消息提示
        /// </summary>
        private ObservableCollection<InstantMsg> msg = new ObservableCollection<InstantMsg>();
        public ObservableCollection<InstantMsg> MSG
        {
            get { return msg; }
            set
            {
                msg = value;
                RaisePropertyChanged("MSG");
            }
        }
        /// <summary>
        /// 扫描历史选中位置
        /// </summary>
        private InstantMsg _ItemSelected;
        public InstantMsg ItemSelected
        {
            get { return _ItemSelected; }
            set
            {
                _ItemSelected = value;
                RaisePropertyChanged("ItemSelected");
            }
        }
        /// <summary>
        /// 显示红灯，绿灯，黄灯
        /// </summary>
        private string _RGYColor = Consts.YELLOW;
        public string RGYColor
        {
            get { return _RGYColor; }
            set
            {
                _RGYColor = value;
                RaisePropertyChanged("RGYColor");
            }
        }
        private string name;
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                RaisePropertyChanged("Name");
            }
        }


        private string selectWaferID;
        public string SelectWaferID
        {
            get { return selectWaferID; }
            set
            {
                selectWaferID = value;
                RaisePropertyChanged("SelectWaferID");
            }
        }
        #endregion

        public string toolTipValue;
        public string ToolTipValue
        {
            get { return toolTipValue; }
            set
            {
                toolTipValue = value;

                RaisePropertyChanged("ToolTipValue");
            }
        }
        private void initClinet()
        {
            var clientInfo = RunService.Current;
            clientInfo.ConnStatus = false;
        }
        public Model.RunService ClientInfo
        {
            get
            {
                return Model.RunService.Current;
            }
        }
        public void ShowMsg(MessageOrigin origin, MessageType type, string detail)
        {
            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
                {
                    if (MSG != null && MSG.Count > 0)
                    {
                        if (MSG[0] != null && !string.IsNullOrEmpty(MSG[0].Detail) && MSG[0].Detail == detail)
                            MSG.RemoveAt(0);
                    }
                    if (MSG.Count >= 1000)
                    {
                        MSG.RemoveAt(999);
                    }
                    MSG.Insert(0, new InstantMsg()
                    {
                        CurTime = DateTime.Now,
                        FrontColor = Consts.MsgColorMap[type],
                        Title = origin,
                        Detail = detail
                    });
                    RaisePropertyChanged("MSG");
                    ItemSelected = MSG[MSG.Count - 1];
                    //App.Current.MainWindow2.FindChild<ListBox>(Name).ScrollIntoView(App.Current.MainWindow2.FindChild<ListBox>(Name).Items[App.Current.MainWindow.FindChild<ListBox>(Name).Items.Count - 1]);
                }));
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }



        private RelayCommand<string> mouseOverCmd;
        public RelayCommand<string> MouseOverCmd
        {
            get
            {
                return mouseOverCmd ?? (mouseOverCmd = new RelayCommand<string>(MouseOver));
            }
        }
        private void MouseOver(string eqpName)
        {
            try
            {
                if (eqpName == "MFDB002")
                {
                    if (ClientInfo.ClientLanguage == "CN")
                    {
                        ClientInfo.Lbl_CarrierID = "批次";
                    }
                    else
                    {
                        ClientInfo.Lbl_CarrierID = "LotID";
                    }
                }
                else
                {
                    if (ClientInfo.ClientLanguage == "CN")
                    {
                        ClientInfo.Lbl_CarrierID = Consts.GetTranslation("Lbl_Lotid");
                    }
                    else
                    {
                        ClientInfo.Lbl_CarrierID = Consts.GetTranslation("Lbl_Lotid");
                    }
                }
                EQPStatus.currenteqpid = eqpName;
                foreach (EqpClientInfo entity in RunService.Current.EquipmentList)
                {
                    if (entity.EqpName == eqpName)
                    {
                        entity.Vis = Visibility.Visible;
                        entity.IsMouseOver = false;
                        entity.MouseMargin = "10,0,0,0";
                        RunService.Current.EQPInfo = entity;
                        RunService.Current.RGYChanged(entity.RGYColor);
                        //var _client = new EAPClient();
                        ////_client.SendConnect(new ConnectModel() { EQPID = eqpName });
                        //var getConn = _client.SendConnect(new ConnectModel() { EQPID = eqpName });
                        //if (getConn!=null&&getConn.ReturnCode == "OK")
                        //{
                        //    entity.ConnStatus = true;
                        //}
                    }
                    else
                    {
                        entity.IsMouseOver = true;
                        entity.Vis = Visibility.Collapsed;
                        entity.MouseMargin = "0,0,0,0";
                    }
                }
                if (RunService.Current.VMFilg)
                {
                    System.Threading.Thread.Sleep(2000);
                    RunService.Current.VMFilg = false;
                }
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
        #region  ClearCurrentLogCmd
        private RelayCommand clearCurrentLogCmd;
        public RelayCommand ClearCurrentLogCmd
        {
            get
            {
                return clearCurrentLogCmd ?? (clearCurrentLogCmd = new RelayCommand(ClearCurrentLog));
            }
        }
        private void ClearCurrentLog()
        {
            try
            {
                MSG.Remove(ItemSelected);
                ListHearMsg = MSG[0].Detail;
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
        #endregion
        #region  ClearAllLogCmd
        private RelayCommand clearAllLogCmd;
        public RelayCommand ClearAllLogCmd
        {
            get
            {
                return clearAllLogCmd ?? (clearAllLogCmd = new RelayCommand(ClearAllLog));
            }
        }
        private void ClearAllLog()
        {
            try
            {
                MSG.Clear();
                ListHearMsg = Consts.GetTranslation("Msg_RealtimeInfo"); ;
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
        #endregion
        /// <summary>
        /// 显示所有LOG
        /// </summary>
        private RelayCommand showAllLogCmd;
        public RelayCommand ShowAllLogCmd
        {
            get
            {
                return showAllLogCmd ?? (showAllLogCmd = new RelayCommand(ShowAllLog));
            }
        }
        private void ShowAllLog()
        {
            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(new Action(delegate
                {
                    GlobalData.Current.EqpName = EqpName;
                    GlobalData.Current.MSG = MSG;
                    Controller.ShowSubWindow(new LogWindowViewModel());
                }));
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
        #region  CopyAllLogCmd
        private RelayCommand _CopyLogCmd;
        public RelayCommand CopyLogCmd
        {
            get
            {
                return _CopyLogCmd ?? (_CopyLogCmd = new RelayCommand(CopyLog));
            }
        }
        private void CopyLog()
        {
            try
            {
                lock (lockobj)
                {
                    if (ItemSelected != null)
                    {
                        CopyMsg += "[" + EqpName + "] " + ItemSelected.CurTime + " " + ItemSelected.Detail + " \r";
                    }
                    if (CopyMsg != "")
                    {
                        Clipboard.SetDataObject(CopyMsg);
                        CopyMsg = "";
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex)); ;
            }
        }
        private RelayCommand _CopyAllLogCmd;
        public RelayCommand CopyAllLogCmd
        {
            get
            {
                return _CopyAllLogCmd ?? (_CopyAllLogCmd = new RelayCommand(CopyAllLog));
            }
        }
        private void CopyAllLog()
        {
            try
            {
                lock (lockobj)
                {
                    if (MSG.Count > 0)
                    {
                        foreach (InstantMsg str in MSG)
                        {
                            CopyMsg += "[" + EqpName + "] " + str.CurTime + " " + str.Detail + " \r";
                        }
                    }
                    if (CopyMsg != "")
                    {
                        Clipboard.SetDataObject(CopyMsg);
                        CopyMsg = "";
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
        #endregion
        #region 显示红灯，绿灯，黄灯
        public string CheckRGY(ProcessState state)
        {
            try
            {
                RGYColor = Consts.YELLOW;
                foreach (var lot in LotList)
                {
                    if (!string.IsNullOrEmpty(lot.LotColor))
                    {
                        if (Convert.ToInt32(Consts.RCYColotMap[lot.LotColor]) > Convert.ToInt32((Consts.RCYColotMap[RGYColor])))
                            RGYColor = lot.LotColor;
                    }
                }
                return RGYColor;
            }
            catch (Exception ex)
            {
                ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
                return Consts.YELLOW;
            }
        }
        #endregion
    }
}
